package com.wwcom.darteagle.model;

import android.util.Log;

public class RunningAverage {
	private int nDarts;
	private float totalScore;
	
	public RunningAverage () {
		nDarts= 0;
		totalScore= 0;
	}	

	public int getNDarts() {
		return nDarts;
	}
	
	public float getTotal() {
		return totalScore;
	}

	public void set(float f, int nDarts) {
		Log.d("RunningAverage","nDarts: "+nDarts+", totalScore: "+f);
		this.nDarts= nDarts;
		this.totalScore= f;
	}

	//scores must have been processed so all thrown darts are >=0 and unthrown darts are == -1
	public void addScores(int []scores) {
		for (int s : scores) {
			if (s>= 0) {
				nDarts++;
				totalScore+= s;
			}
		}
	}
	
	//add single score
	public void add(float f) {
		nDarts++;
		totalScore+= f;
	}
	
	public void addRunningAverage(RunningAverage other) {
		this.nDarts+= other.nDarts;
		totalScore+= other.totalScore;
	}

	public float getCurrentAverage() {
		if (nDarts>0)
			return totalScore/((float)nDarts);
		else
			return 0f;
	}
}
